<?php
class CategoryController extends Controller
{
    function __construct()
    {
        $this->loadLibrary('Utility');
        $this->loadLibrary('Session');
    }

    public function show($id,$page = 1)
    {
        $this->loadModel('category', TRUE);
        $this->loadModel('catindex');
        $this->loadModel('ad',TRUE);
        $data = NULL;

        if(is_null($id))
        {
            Utility::error("Có lỗi xảy ra",'index');
            exit();
        }
		$rs = $this->models['category']->getCategory($id);
		if($rs->getSize() == 0)
		{
			Utility::error("Danh mục không tồn tại",'index');
			exit();
		}
		else
		{
			$data['category'] = $rs->getRow(0);
		}
        $data['news_list'] = $this->models['catindex']->getNewsList($id,$page-1);
        $cat_list = array();
        $this->models['category']->getCategories(0, $cat_list);
        $data['cat_id'] = $id;
        $data['cat_list'] = $cat_list;
        $data['ad_list'] = $this->models['ad']->getAd();
        $data['album_items'] = $this->models['catindex']->getLastestAlbum();
        $data['page'] = $page;
        $view = $this->loadView('news_list');
        if(strcmp(strtolower($data['category']->name),"sự kiện") == 0)        
            $data['current_page'] = 'event';
        else
            $data['current_page'] = 'index';
        $view->setBlockData($data, 'adv');
        $view->setBlockData($data,'menu');
        $view->setBlockData($data, 'cat_list');
        $view->setBlockData($data);
        $view->addJs('jquery.tools.min');
        $view->render();
    }
}